package com.learn.training.multithread.chapter6.minchapter7.demo1;

import java.util.ArrayList;
import java.util.Arrays;

public class Demo {
    public static void main(String[] args) throws InterruptedException {
        Point point = new Point();
        ArrayList<Thread> ts = new ArrayList<Thread>();

        for (int i = 0; i < 5; i++) {
            Thread t = new Thread(){
                public void run(){
                    for (int i = 0; i < 100; i++) {
                        try {
                            point.distanceFromOrigin();
                        }catch (Exception e){
                            return;
                        }
                    }
                }
            };

            t.start();
            ts.add(t);
        }


        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                point.write(i+1, i+1);
                System.out.println(Thread.currentThread().getName() + "  write to  x : " + (i+1) + "  y : " + (i+1));
            }
        });
        t1.start();
        t1.join();

        Thread.sleep(100);
        for (Thread t : ts) {
            t.interrupt();
        }

    }
}
